#include "colors.h"

using namespace cv;
using namespace std;

void FilterColor(Mat &src)
{
    Mat hsv;
    cvtColor(src, hsv, CV_BGR2HSV);//convert the color space
    //Image width and height
    int width = src.cols;
    int height = src.rows;

    Scalar p;
    
    //Loop through pixels
    for (int i = 0; i < width; i++){
        for (int j = 0; j < height; j++){

            int hue = hsv.at<Vec3b>(j, i)[0];
            int sat = hsv.at<Vec3b>(j, i)[1];
            int val = hsv.at<Vec3b>(j, i)[2];
            
            //Check that hue, satiration, and value are outside the acceptable range
            if ( !(  (hue > HUE_MIN) && (hue < HUE_MAX)\
                     && (sat > SAT_MIN) && (sat < SAT_MAX) \
                     && (val > VAL_MIN) && (val < VAL_MAX) ) ) {
                
                //If they are, make it white
                src.at<Vec3b>(j, i)[2] = 255;
                src.at<Vec3b>(j, i)[1] = 255;
                src.at<Vec3b>(j, i)[0] = 255;
            } else {
                //If they are not, make it black
                src.at<Vec3b>(j, i)[2] = 0;
                src.at<Vec3b>(j, i)[1] = 0;
                src.at<Vec3b>(j, i)[0] = 0;
            }                
        }
    }
}

void GreenBalance(Mat &src)
{

    //Image width and height
    int width = src.cols;
    int height = src.rows;
    Vec3b pixel;

    //Loop through pixels
    for (int i = 0; i < width; i++){
        for (int j = 0; j < height; j++) {
            //Make it less green
            unsigned green = src.at<Vec3b>(j,i)[1];
            src.at<Vec3b>(j, i)[1] = (green > 30 ? green - 30 : 0);
        }
    }
}

